<template>
  <div style="padding-top: 80%">
    <loading size="24px" vertical>登录中...</loading>
  </div>
</template>

<script>
import {Loading} from "vant";
import {weChatLogin} from "@/api/home";

export default {
  name: "overview",
  components: {
    Loading
  },
  async created() {
    sessionStorage.setItem("token", '3a597743-6f55-4562-9cac-0a488270d2f3')
    this.$router.push("/home/index");
    return
    const CORPID = 'wx1b07fd672978e23e'; //appid参数
    const REDIRECT_URI = encodeURI('http://dc.shgyjs.cn:1223/#/entering');  //redirect_uri参数
    const AGENTID = '1000012'; //agentid 参数
    const searchParams = new URLSearchParams(window.location.search);
    const code = (this.$route.query.code) || (searchParams.get('code'))
    const state = (this.$route.query.state) || (searchParams.get('state'))
    // 路由上没有code的情况下，进行企业微信授权
    if (!code) {
      const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${CORPID}&redirect_uri=${REDIRECT_URI}&response_type=code&scope=snsapi_privateinfo&state=${state}&agentid=${AGENTID}#wechat_redirect`;
      window.location.href = authUrl;
    } else {
      // 执行登录操作
      await weChatLogin(code).then((res) => {
        if (res.code === 0) {
          sessionStorage.setItem("token", res.data)
          // 有权限，跳转首页
          this.$router.push("/home/index");
        } else {
          // 无权限，跳到无权限页面
          this.$router.push("/error");
        }
      })
    }
    await weChatLogin(code).then((res) => {
      if (res.code === 0) {
        sessionStorage.setItem("token", res.data)
        // 有权限，跳转首页
        this.$router.push("/home/index");
      } else {
        // 无权限，跳到无权限页面
        this.$router.push("/error");
      }
    })
  },
};
</script>

<style lang="scss" scoped></style>
